package com.example.demo.his.leetcode;

/**
 * @auther zzc
 * @date 2021/4/9 15:10
 */
public class 实现strStr {
    //两个字符串  找出b在a中出现的第一个位置
    //输入a='hello' b='ll'
    //输出  2
    public static void main(String[] args) {
        String a = "fzzc";
        String b = "zzc";
        System.out.println(strStr(a, b));
    }

    private static int strStr(String a, String b) {
        int length1 = a.length();
        int length2 = b.length();
        for (int i = 0; i < length1 - length2 + 1; i++) {
            if ((a.substring(i, (i + length2)).equals(b))) {
                return i;
            }
        }
        return 0;
    }
}
